package com.cytech.cloudclinic.moudle.main.expert;

import android.view.View;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.adapter.ExpertAdapter;
import com.cytech.cloudclinic.base.BaseFragment;
import com.cytech.cloudclinic.bean.Expert;
import com.yechaoa.yutils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ExportFragment extends BaseFragment<ExportPresenter> implements ExportView {

    @BindView(R.id.rg_expert_manager)
    RadioGroup rgAdmissionManager;
    @BindView(R.id.rv_expert_main)
    RecyclerView rvExpertMain;

    private List<Expert> expertList;
    private ExpertAdapter mAdapter;
    //1=中医，2=西医
    private int type;

    public static ExportFragment newInstance() {
        ExportFragment fragment = new ExportFragment();
        //如果有参数，使用Bundle传递
        return fragment;
    }


    @Override
    protected ExportPresenter createPresenter() {
        return new ExportPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main_expert;
    }

    @Override
    protected void initView() {
        rgAdmissionManager.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i){
                    case R.id.rb_expert_1:
                        type = 1;
                        presenter.getExportList(type);
                        break;
                    case R.id.rb_expert_2:
                        type = 2;
                        presenter.getExportList(type);
                        break;
                }
            }
        });
    }

    @Override
    protected void initData() {
        expertList = new ArrayList<>();
        mAdapter = new ExpertAdapter(expertList);
        rvExpertMain.setLayoutManager(new GridLayoutManager(getActivity(),5));
        rvExpertMain.setAdapter(mAdapter);

        mAdapter.addChildClickViewIds(R.id.item_ask_now);
        mAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                ToastUtil.showToast("暂未开发，请稍候");
            }
        });

        presenter.getExportList(type);
    }

    @Override
    public void getExportListSuccess(List<Expert> data) {
        mAdapter.setNewInstance(data);
    }
}
